*********************************
*** JOP paper: Historical memory and radical right voting: VOX and the legacy of Francoism
*** Anja Neundorf and Sergi Pardos Prado
*** Do-file: DATA PREPERATION
*** Created: 21/02/2022
*** Last updated: 21/03/2024

use VoxData.dta

** -----------
* Dropping cases that did not give consent
tab1 consent_nonAmazon consent_Amazon150 consent_Amazon10
tab1 consent_nonAmazon consent_Amazon150 consent_Amazon10, nolabel

drop if consent_nonAmazon==2 | consent_Amazon150==2 | consent_Amazon10==2 

** -----------
** Setting all Don't knows to missings 
mvdecode _all, mv(999=.)


** -----------------------
** Recode PTV variables

corr ptv_2 ptv_3

* PSOE
gen psoe_sup = 0
replace psoe_sup = 1 if ptv_1>5
replace psoe_sup = . if ptv_1==.

* PP
gen pp_sup = 0
replace pp_sup = 1 if ptv_2>5
replace pp_sup = . if ptv_2==.


* Ciudadanos
gen ciu_sup = 0 
replace ciu_sup = 1 if ptv_4>5
replace ciu_sup = . if ptv_4==.

* Podemos
gen pod_sup = 0
replace pod_sup = 1 if ptv_5>5
replace pod_sup = . if ptv_5==.

* VOX
gen vox_sup = 0
replace vox_sup = 1 if ptv_3>5 
replace vox_sup = . if ptv_3==.

tab  vote2019 vox_sup
tab  ptv_3 vox_sup

tab  pp_sup vox_sup, col

gen vox_sup_right = 0 if pp_sup==1 | ciu_sup==1
replace vox_sup_right = 1 if ptv_3>5 
replace vox_sup_right = . if ptv_3==.

tab vox_sup_right


** Look at all parties

tab1 psoe_sup pp_sup vox_sup ciu_sup pod_sup


** -----------------------
** Recode vote variables

tab vote2019, gen(vote_)
tab vote2019, nolabel

gen vote_vox_right = 0 if vote2019==2 | vote2019==5
replace vote_vox_right = 1 if vote2019==3
tab vote_vox_right vote2019

** -----------------------
** Recode Support treatment variables

tab treatment
tab treatment, nolabel

tab1 t5_union t4_femin t3_immig t2_catalan t1_franco t0_prado


gen support = .
replace support = t5_union if treatment == "union"
replace support = t4_femin if treatment == "femin"
replace support = t3_immig if treatment == "immig"
replace support = t2_catalan if treatment == "catalan"
replace support = t1_franco if treatment == "franco"
replace support = t0_prado if treatment == "prado"


tab support
gen supp01 = (support-1)/5
sum supp01 
 
gen treat = .
replace treat = 5 if treatment == "union"
replace treat = 4 if treatment == "femin"
replace treat = 3 if treatment == "immig"
replace treat = 2 if treatment == "catalan"
replace treat = 1 if treatment == "franco"
replace treat = 0 if treatment == "prado"


lab def treatlbl 0 "Prado" 1 "Franco" 2 "Catalan" 3 "Immigration" 4 "Feminism" 5 "Unions"
lab val treat treatlbl

tab treatment treat


** -----------------------
** Recode behavioural outcome

tab1 donate_nonamazon150 donate_nonamazon10  donate_amazon150 donate_amazon10 donate_amount150__15 donate_amount10_15 donate_amount175_15

gen don = .
replace don = donate_nonamazon150 if donate_nonamazon150!=.
replace don = donate_nonamazon10 if donate_nonamazon10!=.
replace don = donate_amazon150 if donate_amazon150!=.
replace don = donate_amazon10 if donate_amazon10!=.


recode don (1=0 "No donation") (2=1 "Donate money"), gen(donate)
drop don
tab donate

* Amount
gen don_pc_10 = (donate_amount10_15 / 10)*100
gen don_pc_150 = (donate_amount150__15 / 150)*100
gen don_pc_175 = (donate_amount175_15 / 175)*100

sum don_pc_10 don_pc_150 don_pc_175

gen amount_pc = .
replace amount_pc = don_pc_10 if don_pc_10!=.
replace amount_pc = don_pc_150 if don_pc_150!=.
replace amount_pc = don_pc_175 if don_pc_175!=.
sum amount_pc

gen amount150 = .
replace amount150 = 0 if donate_amount10_15!=. 
replace amount150 = 1 if donate_amount150__15!=. | donate_amount175_15!=.

** -----------------------
** Recode observed outcomes

* democracy support

tab dembest
recode dembest (1=1) (2/3=0), gen(dembest_dum)
tab dembest dembest_dum
recode dembest_dum (1=0) (0=1), gen(autoc_dum)


tab demimp
gen demimp01 = (demimp-1)/6
sum demimp01


* Immigration
tab imm

* Populism
tab1  Q14_1 Q14_4
corr Q14_1 Q14_4
alpha Q14_1 Q14_4

egen populism = rowmean(Q14_1 Q14_4)
sum populism

* Nationalism
tab nationalism
tab nationalism, nolabel
recode nationalism (8=.)


** -----------------------
** Recode control variables

* gender
tab gender
tab gender, nolabel
recode gender (1=0 "male") (2=1 "female") (3=0), gen(female) 

* education 
tab education
tab education, nolabel

recode education (1/2=0 "No/primary") (3=1 "secondary") (4=3 "degree") (5=2 "vocational") (6=4 "Other"), gen(educ)

* income
tab income

* polint
tab polint 

* age
tab age

capture drop birth
gen birth = 2021-age

* domicile
tab domicile


*-------------------
*** AD CAMPAIGNS

tab utm_campaign
tab utm_campaign, nolabel

capture drop ads

gen ads = 0 if utm_campaign=="Spain 2022: base new" | utm_campaign=="Spain 2022: base"
replace ads = 1 if utm_campaign=="Spain 2022: no incentives" | utm_campaign=="Spain 2022: political image 3 additional"
replace ads = 2 if utm_campaign=="Spain 2022: Amazon 10" | utm_campaign=="Spain 2022: 10 Euros new"
replace ads = 3 if utm_campaign=="Spain 2022: Amazon 150" | utm_campaign=="Spain 2022: 175 Euros new"
 
lab def adlbl 0 "Base" 1 "No incentives" 2 "Incentives: low" 3 "Incentives: high" 
lab val ads adlbl

tab utm_campaign ads 


*-------------------
*** SAVE RECODED DATA

save "Spain_Vox_recoded.dta", replace



